<template>
  <div class="container">
    <div class="content">
      <div class="content-group" v-for="(item, index) in list" :key="index">
        <div class="content-group-box">
          <div class="content-group-item">
            <uni-row>
              <uni-col :span="6"> 套餐名称 </uni-col>
              <uni-col :span="18">
                {{ item.name }}
              </uni-col>
            </uni-row>
          </div>
          <div class="content-group-item">
            <uni-row>
              <uni-col :span="6"> 预约日期 </uni-col>
              <uni-col :span="18">
                {{ item.date }}
              </uni-col>
            </uni-row>
          </div>
        </div>
        <div class="qr-code">
          <uni-tag
            text="查看体检码"
            type="primary"
            @click="handleViewQRCode(item)"
          />
        </div>
      </div>
    </div>
    <view>
      <uni-popup ref="getQEDialog" type="dialog">
        <uni-popup-dialog
          title="查看体检码"
          type="info"
          content="请使用微信扫码查看体检码"
          :showCancelButton="false"
          @confirm="closeDialog"
        >
          <canvas class="view-qr-code" canvas-id="myQrcode"></canvas>
        </uni-popup-dialog>
      </uni-popup>
    </view>
  </div>
</template>

<script>
import drawQrcode from "@/utils/weapp.qrcode.esm.js";
// import drawQrcode from "@/utils/weapp-qrcode.js";
export default {
  data() {
    return {};
  },
  computed: {
    list() {
      return Array(3).fill({
        name: "新生体检",
        date: "2024年7月5日14:21:06",
        QRCode: "11111",
      });
    },
  },
  methods: {
    // 获取二维码
    getQECode(item) {
      drawQrcode({
        width: 200,
        height: 200,
        canvasId: "myQrcode",
        background: "#ffffff", //	非必须，二维码背景颜色，默认值白色
        foreground: "#2979ff", // 非必须，二维码前景色，默认值黑色 	'#000000'
        text: item.QRCode,
        image: {
          imageResource: "../../static/logo.png", // 指定二维码小图标
          dx: 70,
          dy: 70,
          dWidth: 60,
          dHeight: 60,
        },
      });
    },
    // 查看二维码
    handleViewQRCode(item) {
      this.$refs.getQEDialog.open();
      this.getQECode(item);
    },
    // 关闭弹窗
    closeDialog() {
      this.$refs.getQEDialog.close();
    },
  },
};
</script>

<style lang="scss" scoped>
.content {
  border-radius: 8px;
  margin-bottom: 1rem;
}

.content-group {
  border-radius: 8px;
  margin: 0.625rem;
  border: 1px solid #ebeef5;
  background-color: #fff;
  box-shadow: 0 2px 12px 0 rgba(151, 203, 245, 0.5);
  display: flex;
}
.content-group-box {
  width: 70vw;
}
.qr-code {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 30vw;
}
.content-group-item {
  padding: 10px;
  font-size: 12px;
}
.view-qr-code {
  width: 200px;
  height: 200px;
  margin: 0 auto;
}
</style>